package com.bawei.http

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import javax.inject.Singleton

@Module //声明当前是一个Hilt模块
@InstallIn(SingletonComponent::class) //声明当前类的作用域是整个应用
object HttpHiltModel {


    @CommonHttpClientAnnotation
    @Provides  //声明提供
    @Singleton //声明单例
    fun provideCommonOkHttpClient(): OkHttpClient{
        return ClientManager.createCommonOkHttpClient()
    }

    @TokenHttpClientAnnotation
    @Provides  //声明提供
    @Singleton //声明单例
    fun provideTokenOkHttpClient(): OkHttpClient{
        return ClientManager.createTokenOkHttpClient()
    }

    @CommonHttpsClientAnnotation
    @Provides  //声明提供
    @Singleton //声明单例
    fun provideCommonOkHttpsClient(): OkHttpClient{
        return ClientManager.createCommonOkHttpsClient()
    }

    @TokenHttpsClientAnnotation
    @Provides  //声明提供
    @Singleton //声明单例
    fun provideTokenOkHttpsClient(): OkHttpClient{
        return ClientManager.createTokenOkHttpsClient()
    }

    @CommonHttpRetrofitAnnotation
    @Provides  //声明提供
    @Singleton //声明单例
    fun provideCommonOkHttpRetrofit(@CommonHttpClientAnnotation client: OkHttpClient): Retrofit{
        return RetrofitManager.getRetrofit(client)
    }

    @TokenHttpRetrofitAnnotation
    @Provides  //声明提供
    @Singleton //声明单例
    fun provideTokenOkHttpRetrofit(@TokenHttpClientAnnotation client: OkHttpClient): Retrofit{
        return RetrofitManager.getRetrofit(client)
    }

    @CommonHttpsRetrofitAnnotation
    @Provides  //声明提供
    @Singleton //声明单例
    fun provideCommonOkHttpsRetrofit(@CommonHttpsClientAnnotation client: OkHttpClient): Retrofit{
        return RetrofitManager.getRetrofit(client)
    }

    @TokenHttpsRetrofitAnnotation
    @Provides  //声明提供
    @Singleton //声明单例
    fun provideTokenOkHttpsRetrofit(@TokenHttpsClientAnnotation client: OkHttpClient): Retrofit{
        return RetrofitManager.getRetrofit(client)
    }

}